最后编辑于: 2015-10-18 14:47 | 分类: linux | 标签: | 浏览数: 964 | 评论数: 0
xargs
是给命令传递参数的一个过滤器,也是组合多个命令的一个工具。
它把一个数据流分割为一些足够小的块,以方便过滤器和命令进行处理。
通常情况下,xargs从管道或者stdin中读取数据,但是它也能够从文件的输出中读取数据。
xargs的默认命令是echo,这意味着通过管道传递给xargs的输入将会包含换行和空白,不过通过xargs的处理,换行和空白将被空格取代。
xargs
是一个强有力的命令,它能够捕获一个命令的输出,然后传递给另外一个命令,下面是一些如何有效使用xargs的实用例子。
# find ~ -name ‘*.log’ -print0 | xargs -0 rm -f
# find /etc -name "*.conf" | xargs ls –l
# cat url-list.txt | xargs wget –c
# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
# ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory